<html>
<head><meta charset="utf-8"><title>What is Display for? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html">What is Display for?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211103929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211103929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211103929">(Sep 24 2020 at 08:50)</a>:</h4>
<p>It has been said that <code>Display</code> is for showing output to users. This confuses me. The trait is very inflexible, you're stuck with whatever the library author decided. This can lead to inconsistent output if you pull in many different crates with different ideas for their display strings. It also doesn't allow for adjusting the output for the context.</p>
<p>In general it doesn't allow for translations (in both the sense of formatting and in the sense of language and locale). To me this suggests it's more for quick 'n dirty output or for when there's very obviously only one string representation of the type.</p>
<p>Have I misunderstood this trait?</p>



<a name="211104334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211104334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211104334">(Sep 24 2020 at 08:55)</a>:</h4>
<p>yeah, it's true that Display trait not support localization. <br>
However, Display do what crate author decided for their types is good, since if the members of that type is private,<br>
how can you access it to do your own Display ?</p>



<a name="211104547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211104547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211104547">(Sep 24 2020 at 08:57)</a>:</h4>
<p>I think that's a problem I have with it. If the <code>Display</code> string includes details not otherwise accessible then if you want to do any customization or localization you end up having to parse the string... which is far from ideal.</p>



<a name="211147169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211147169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211147169">(Sep 24 2020 at 15:22)</a>:</h4>
<p>You're not wrong, the design of <code>Display</code> is mostly "not that good"</p>



<a name="211150334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211150334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DPC <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211150334">(Sep 24 2020 at 15:46)</a>:</h4>
<p>well it makes sense that the crate which defines the type should define how the type is displayed. Besides that orphan rules might be another problem you'll encounter</p>



<a name="211319991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211319991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211319991">(Sep 25 2020 at 21:28)</a>:</h4>
<p>IMHO read <code>Display</code> as "a human readable representation more close to natural language then debug".</p>
<p>I.e. it's not at all build to be used for a user interface. Through it might work for a cli. </p>
<p>I think it's mainly useful for logging or (not end-user facing) error messages for e.g. error reports.</p>
<p>I.e. anything facing IT people.</p>
<p>Btw. there should not be be any runtime information only available through Display formatting, I would treat that as a bug. (Through one which can happen very easy).</p>



<a name="211320613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211320613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211320613">(Sep 25 2020 at 21:34)</a>:</h4>
<blockquote>
<p>Btw. there should not be be any runtime information only available through Display formatting, I would treat that as a bug. (Through one which can happen very easy).</p>
</blockquote>
<p><a href="https://github.com/launchbadge/sqlx/pull/701">https://github.com/launchbadge/sqlx/pull/701</a></p>



<a name="211351982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211351982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211351982">(Sep 26 2020 at 09:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209646">Philipp Korber</span> <a href="#narrow/stream/122651-general/topic/What.20is.20Display.20for.3F/near/211319991">said</a>:</p>
<blockquote>
<p>I think it's mainly useful for logging or (not end-user facing) error messages for e.g. error reports.</p>
</blockquote>
<p>Thanks! So perhaps a better slogan is "Display is for logs"? While this isn't the full extent of what it's used for, it is perhaps a better mindset than the vague "for users".</p>



<a name="211358803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211358803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211358803">(Sep 26 2020 at 12:55)</a>:</h4>
<p>I feel like that's confusing because Debug is also sometimes used for logs :/</p>



<a name="211360324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211360324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211360324">(Sep 26 2020 at 13:34)</a>:</h4>
<p>It is, I think the important takeaway is that display isn't designed for being used for a end user facing UI as it's basically debug but more human readable. But end user facing UI need much more than that (like localization, potential contextual changes like short and long info, potential non utf-8 encoding, potential non-string output (e.g. multiple UI elements), potential interactive components, ..) and I'sure having a single trait which tried to cover all of this is a bad idea.</p>
<p>In a certain way Display is the <em>most</em> minimal viable common dominator, but in turn also only useable in very limited use-cases.</p>



<a name="211363267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211363267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211363267">(Sep 26 2020 at 14:45)</a>:</h4>
<p>"Display is for English, utf-8, textual logs aimed at non-Rustaceans"</p>



<a name="211364008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211364008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211364008">(Sep 26 2020 at 15:01)</a>:</h4>
<p><code>Display</code> is also used in the blanket <code>ToString</code>, and ideally should mirror <code>FromStr</code></p>



<a name="211364292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211364292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211364292">(Sep 26 2020 at 15:06)</a>:</h4>
<p>and <code>FromStr</code> is also used by <code>str::parse</code>, so together this is like human-readable serialization</p>



<a name="211364955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211364955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211364955">(Sep 26 2020 at 15:20)</a>:</h4>
<p>I think that, unfortunately, Display probably doesn't have the info to re-parse the value you started with (though Debug might)</p>



<a name="211368476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211368476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211368476">(Sep 26 2020 at 16:38)</a>:</h4>
<p>So <code>Display</code> is pulling double duty? This may explain some of my frustrations with it because it sounds like it's used for very different things depending on the author.</p>



<a name="211368617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211368617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211368617">(Sep 26 2020 at 16:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="260325">Chris Denton</span> <a href="#narrow/stream/122651-general/topic/What.20is.20Display.20for.3F/near/211104547">said</a>:</p>
<blockquote>
<p>I think that's a problem I have with it. If the <code>Display</code> string includes details not otherwise accessible then if you want to do any customization or localization you end up having to parse the string... which is far from ideal.</p>
</blockquote>
<p>Maybe I'm wrong, but would you ever want to expose those private details to the user through a  <code>Display</code>ed string?</p>



<a name="211368706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211368706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211368706">(Sep 26 2020 at 16:43)</a>:</h4>
<p>(Not saying you're wrong of course, just thinking that those details should maybe be public if they'd need to be displayed to the user)</p>



<a name="211369520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211369520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211369520">(Sep 26 2020 at 17:04)</a>:</h4>
<p>Yeah <code>Display</code> is very under specified, so it means many things to many people.</p>



<a name="211373304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211373304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211373304">(Sep 26 2020 at 18:39)</a>:</h4>
<p>The way I originally heard it described was that <code>Debug</code> should look exactly like code to the extent possible, while <code>Display</code> is allowed to make it somewhat more readable.</p>



<a name="211385849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211385849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211385849">(Sep 26 2020 at 22:41)</a>:</h4>
<p>plausible, but then <em>maybe</em> FromStr and parse and friends should key off of the Debug formatting instead.</p>



<a name="211388573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211388573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Karel Kubat <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211388573">(Sep 27 2020 at 00:00)</a>:</h4>
<p>In that case, it seems that rust's Debug = haskell's Show?</p>



<a name="211388668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211388668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211388668">(Sep 27 2020 at 00:03)</a>:</h4>
<p>for derived instances of <code>Show</code>, yes. <code>Show</code> itself does not specify conceptual requirements or properties of its output the way Rust does.</p>



<a name="211388737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211388737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Karel Kubat <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211388737">(Sep 27 2020 at 00:05)</a>:</h4>
<p>I'm only aware of derived instances, but I assumed Show is always supposed to produce valid Haskell.</p>



<a name="211390285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211390285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211390285">(Sep 27 2020 at 00:52)</a>:</h4>
<p>Show should produce whatever Read accepts, if you have Read for your type, and otherwise it's still probably a valid Haskell literal for the type if possible just to make putting it back into ghci easier.</p>
<p>Myself, usually if I do Display at all it just shows the Debug anyway. I'm a menace to crates everywhere.</p>



<a name="211390804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211390804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211390804">(Sep 27 2020 at 01:09)</a>:</h4>
<p>perhaps the most prominent instance where I ever implement Display is for <code>Error</code> impls.</p>



<a name="211391508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211391508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211391508">(Sep 27 2020 at 01:30)</a>:</h4>
<p>I do it for number types, and also yes if you want to impl Error.</p>
<p>Honestly, if the <code>{}</code> formatter would just use the hekkin Debug impl when Display isn't available on the type I would never again have a strong opinion about Display.</p>



<a name="211391847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211391847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucius Hu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211391847">(Sep 27 2020 at 01:38)</a>:</h4>
<p>I had a solver for minesweeper. I actually have Display to show a colored grid representing the board, mines, and flags, with line and column index on the edge</p>



<a name="211391851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211391851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucius Hu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211391851">(Sep 27 2020 at 01:38)</a>:</h4>
<p>Display is very versatile and up to the developer to decide what to show</p>



<a name="211392725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211392725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211392725">(Sep 27 2020 at 02:02)</a>:</h4>
<p>Well ultimately the real problem is that we can't define our own formatters</p>



<a name="211396877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211396877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Quy Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211396877">(Sep 27 2020 at 03:59)</a>:</h4>
<p>It's such a pain because some common things like Vec don't  implement Display. I really wish Rust had better newtypes where DebugAsDisplay&lt;T&gt; or something would just work :(</p>



<a name="211399132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211399132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucius Hu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211399132">(Sep 27 2020 at 05:08)</a>:</h4>
<p>what's the scenario that you can't use "{:?}"?</p>



<a name="211399625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211399625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211399625">(Sep 27 2020 at 05:24)</a>:</h4>
<p>You always can, but every time i want to quickly print "the thingy is {}" and have it <em>just work</em>, nope, gotta go back and add the extra <code>:?</code> in the middle. every time.</p>



<a name="211403281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211403281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lucius Hu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211403281">(Sep 27 2020 at 07:28)</a>:</h4>
<p>maybe add a {:??}, use Display if implemented, otherwise Debug</p>



<a name="211404394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211404394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211404394">(Sep 27 2020 at 08:03)</a>:</h4>
<p>With (generalized) auto-ref based specialization it is well possible to have a proc-macro implementation of println and friends that make <code>"{}"</code> behave as <code>"{:?}"</code> for non-displayables</p>



<a name="211406204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211406204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Goat <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211406204">(Sep 27 2020 at 08:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="303115">Quy Nguyen</span> <a href="#narrow/stream/122651-general/topic/What.20is.20Display.20for.3F/near/211396877">said</a>:</p>
<blockquote>
<p>I really wish Rust had better newtypes where DebugAsDisplay&lt;T&gt; or something would just work :(</p>
</blockquote>
<p>The <a href="https://docs.rs/fmt_adapter/0.2.1/fmt_adapter/"><code>fmt_adapter</code></a> crate that I made serves this specific purpose</p>



<a name="211421603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211421603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211421603">(Sep 27 2020 at 15:38)</a>:</h4>
<p><span class="user-mention" data-user-id="346097">@Lucius Hu</span> that is literally the opposite of what I want XD</p>



<a name="211427948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211427948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DPC <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211427948">(Sep 27 2020 at 18:20)</a>:</h4>
<p>if you want to quickly print something esp for debugging use, use should be using Debug in the first place  <span aria-label="stuck out tongue" class="emoji emoji-1f61b" role="img" title="stuck out tongue">:stuck_out_tongue:</span></p>



<a name="211428412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211428412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211428412">(Sep 27 2020 at 18:33)</a>:</h4>
<p>I think you're misunderstanding the scenario I'm going for. When I say "quickly" I mean "typing less". So anything that requires typing more isn't as good. What I want  is for<code>{}</code> to just "always work somehow", and use Display if it's there, and Debug if it's not, and heck just print the type name and nothing else if there's no Debug for whatever reason. Particularly, I want to be able to not have to remember "oh <code>x</code> is an i32 and so it's Display but <code>pos</code> is a [i32;2] and so it's not Display and i have to write the stupid extra <code>:?</code> in there".</p>



<a name="211430869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211430869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211430869">(Sep 27 2020 at 19:35)</a>:</h4>
<p>IMHO typing slightly less should never be a motivation for a feature.</p>
<p>The only place where I thing "{}" always magically working is really helpful  is for println debugging. But for that we have <code>dbg!</code>.</p>
<p>At least I would prefer <code>{}</code> not working if there is no explicit <code>Display</code> implementation. (Through I belive every public type should have a <code>Debug</code> implementation.)</p>
<p>Anyway just my personal preferences  <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="211430927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211430927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211430927">(Sep 27 2020 at 19:36)</a>:</h4>
<p><code>dbg!</code> is unfortunately quite poor for println debugging because it uses the alternate formatting flag.</p>



<a name="211432585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211432585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211432585">(Sep 27 2020 at 20:14)</a>:</h4>
<p>Is leaving <code>#[derive(Debug)]</code> in production code bad practice?</p>



<a name="211432618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211432618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211432618">(Sep 27 2020 at 20:15)</a>:</h4>
<p>Not at all.</p>



<a name="211432621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211432621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211432621">(Sep 27 2020 at 20:15)</a>:</h4>
<p>If nothing calls it, it'll generate no code.</p>



<a name="211432628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211432628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211432628">(Sep 27 2020 at 20:15)</a>:</h4>
<p>And it's helpful for things like <code>assert_eq!</code>, or <code>dbg!</code>, or other such things you might need in your code when debugging it.</p>



<a name="211432683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211432683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211432683">(Sep 27 2020 at 20:16)</a>:</h4>
<p>On the contrary, in general if a structure <em>can</em> have <code>Debug</code> derived, I'd generally do so unless there's some specific reason not to.</p>



<a name="211432697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211432697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211432697">(Sep 27 2020 at 20:16)</a>:</h4>
<p>Yeah i consider it a bug to <em>not</em> have Debug.</p>



<a name="211433174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211433174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211433174">(Sep 27 2020 at 20:29)</a>:</h4>
<p>I think <code>winapi</code> tried having <code>Debug</code> on everything by default but it destroyed compile times? Really big crate though.</p>



<a name="211433708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211433708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211433708">(Sep 27 2020 at 20:43)</a>:</h4>
<p>correct</p>



<a name="211434011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211434011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211434011">(Sep 27 2020 at 20:51)</a>:</h4>
<p>Yeah, those types are concrete so not only is it the cost of the macro to generate all that code and the cost to parse it all, but it'd actually codegen all those impls too.  (Almost all of which the linker would then throw out when you actually use the thing.)</p>



<a name="211440330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211440330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DPC <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211440330">(Sep 27 2020 at 23:41)</a>:</h4>
<p>winapi is generally an <em>exception</em>  in various cases</p>



<a name="211450393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211450393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ahmed Charles <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211450393">(Sep 28 2020 at 04:15)</a>:</h4>
<p>I think <code>Display</code> is what you implement when you want to pass a type to <code>format_args!</code> but you don't like what the <code>#[derive(Debug)]</code> looks like for that type.</p>



<a name="211450613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211450613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ahmed Charles <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211450613">(Sep 28 2020 at 04:20)</a>:</h4>
<p>I think it's amusing in that I've never written a <code>Display</code> impl proactively and what it looks like when I do write it is always motivated by the location where I'm calling <code>format_args!</code>.</p>



<a name="211452718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211452718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211452718">(Sep 28 2020 at 05:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281739">Oliver</span> <a href="#narrow/stream/122651-general/topic/What.20is.20Display.20for.3F/near/211432585">said</a>:</p>
<blockquote>
<p>Is leaving <code>#[derive(Debug)]</code> in production code bad practice?</p>
</blockquote>
<p>A reasonable compromise is to put it on public types.</p>



<a name="211480847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211480847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211480847">(Sep 28 2020 at 11:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="260325">Chris Denton</span> <a href="#narrow/stream/122651-general/topic/What.20is.20Display.20for.3F/near/211433174">said</a>:</p>
<blockquote>
<p>I think <code>winapi</code> tried having <code>Debug</code> on everything by default but it destroyed compile times? Really big crate though.</p>
</blockquote>
<p>In that (rare) case, the solution is to feature-gate the <code>Debug</code> impls, so that downstream users can opt into longer compile-times but  with provided <code>Debug</code> impls, like <a href="https://docs.rs/syn/1.0.42/syn/#optional-features"><code>::syn</code> does</a></p>
<p><span class="user-mention silent" data-user-id="209646">Philipp Korber</span> <a href="#narrow/stream/122651-general/topic/What.20is.20Display.20for.3F/near/211430869">said</a>:</p>
<blockquote>
<p>(Through I belive every public type should have a <code>Debug</code> implementation.)</p>
<p>Anyway just my personal preferences  <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>
</blockquote>
<p>FWIW, there is <a href="https://doc.rust-lang.org/beta/rustc/lints/listing/allowed-by-default.html#missing-debug-implementations"><code>#![warn(missing_debug_implementations)]</code></a> to help spot that (sadly it does not take into account privacy). With this lint, you instead explicitly opt out of having <code>Debug</code> when it doesn't make sense to do so (with <code>#[allow(missing_debug_implementations)]</code>), which helps prevent oversights <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="211481551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/What%20is%20Display%20for%3F/near/211481551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/What.20is.20Display.20for.3F.html#211481551">(Sep 28 2020 at 11:51)</a>:</h4>
<p>(deleted)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>